package com.wsoft.form.controller;

import com.wsoft.form.manager.WfFormColumnLinkManager;
import com.wsoft.form.query.table.TableListQuery;
import com.wsoft.form.service.IWfFormTableService;
import com.wsoft.form.service.IWfFormVirtualColumnService;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collections;

/**
 * 设计表的时候 需要获取的接口
 * @Author z001
 * @Date 2024/12/27 08:47
 */
@RestController
@Tag(name = "设计表-调用相关接口")
@RequestMapping("/wf/design")
public class WfDesignController {

    @Resource
    private WfFormColumnLinkManager linkManager;
    @Resource
    private IWfFormTableService tableService;
    @Resource
    private IWfFormVirtualColumnService virtualColumnService;


    @Operation(summary = "获取form下的所有表", description = "获取form下的所有表")
    @GetMapping("/getByFormId")
    public ResponseResult getByFormId(@RequestParam("formId") Long formId) {
        TableListQuery query = new TableListQuery();
        query.setFormId(formId);
        return ResponseResult.success(tableService.listTable(query));
    }

    @Operation(summary = "获取table下所有字段", description = "获取table下所有字段")
    @GetMapping("/getColumn")
    public ResponseResult getColumn(@RequestParam("tableId") Long tableId) {
        return ResponseResult.success(tableService.getColumnList(tableId));
    }

    @Operation(summary = "获取table下所有虚拟字段", description = "获取table下所有虚拟字段")
    @GetMapping("/getColumnAll")
    public ResponseResult getColumnAll(@RequestParam("tableId") Long tableId) {
        return ResponseResult.success(virtualColumnService.listVirtualColumn(tableId));
    }

    @Operation(summary = "获取column的关联信息", description = "获取column的关联信息")
    @GetMapping("/getColumnLink")
    public ResponseResult getColumnLink(@RequestParam("columnId") Long columnId) {
        return ResponseResult.success(linkManager.getByColumnId(Collections.singletonList(columnId)));
    }





}
